#ifndef STOPWATCH_CONTAINER_H_INCLUDED
#define STOPWATCH_CONTAINER_H_INCLUDED

#include <coecntrl.h>
#include "TimeFormatter.h"

class MEikCommandObserver;
class CEikTextListBox;
class CEikLabel;
class CAknsBasicBackgroundControlContext;

class CStopWatchContainer : public CCoeControl
{
public:
  CStopWatchContainer();
  static CStopWatchContainer* NewL(const TRect& aRect, const CCoeControl* aParent, MEikCommandObserver* aCommandObserver, TTimeIntervalMicroSeconds aInitialValue = TTimeIntervalMicroSeconds(0));
  static CStopWatchContainer* NewLC(const TRect& aRect, const CCoeControl* aParent, MEikCommandObserver* aCommandObserver, TTimeIntervalMicroSeconds aInitialValue = TTimeIntervalMicroSeconds(0));
  void ConstructL(const TRect& aRect, const CCoeControl* aParent, MEikCommandObserver* aCommandObserver, TTimeIntervalMicroSeconds aInitialValue = TTimeIntervalMicroSeconds(0));
  virtual ~CStopWatchContainer();

  TInt CountComponentControls() const;
  CCoeControl* ComponentControl(TInt aIndex) const;
  TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType);
  void HandleResourceChange(TInt aType);

  static void CreateListBoxItemL(TDes& aBuffer, TInt aItemId, const TDesC& aTime1Text);
  void SetDisplayValueL(const TTimeIntervalMicroSeconds& aValue);
  void AddTimeSnapshotL(const TTimeIntervalMicroSeconds& aSnapshot);
  void SetSnapshotsL(const TArray<TTimeIntervalMicroSeconds>& aSnapshot);
  void ResetTimeSnapshots();

private:
  void SizeChanged();
  TTypeUid::Ptr MopSupplyObject(TTypeUid aId);
  void Draw(const TRect& aRect) const;

  void InitializeControlsL();
  void LayoutControls();
  void SetLabelTextColorL();
  void AdjustLabelFontL(TInt aWidth);
  void AdjustLabelFontL(TInt aWidth, TInt aNumberofVisibleChars);
  CCoeControl* iFocusControl;
  MEikCommandObserver* iCommandObserver;


private:
  CEikTextListBox* iListBox;
  CEikLabel* iTimeLabel;
  CFont* iFont;
  CAknsBasicBackgroundControlContext* iBackground;

  TTimeFormatter iTimeFormatter;

  CAsyncCallBack* iCallback;

  void ScheduleChangeFontSize();
  static TInt ChangeFontSizeCb(TAny* aThis);
  void ChangeFontSizeL();

public:
  enum TControls
  {
    EListBox,
    ETimeLabel,
    ELastControl
  };

};

#endif // STOPWATCH_CONTAINER_H_INCLUDED
